<template>
  <el-table
      :data="useSignTable"
      header-align="center"
      v-loading="loading"
      element-loading-text="请稍等...">
    <el-table-column prop="antiFakeSealId" label="防伪印章ID" />
    <el-table-column prop="antiFakeUser" label="导出人"  />
    <el-table-column prop="antiFakeTime" label="导出时间"  />
    <el-table-column label="操作" align="center" width="200px">
      <template #default="scope">
        <el-button type="text" size="small" @click="getDetail(scope.$index, scope.row)">详情</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
      :page-sizes="[10, 15, 20, 25]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalNum"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      align="center"
  >
  </el-pagination>
</template>

<script setup>
import {
  getSignDetailByUserApi, getSignDetailNumByUserApi,
} from '../../../api/sealAntiFake';
import {dateFormat} from '../../../utils/util';
import {ElMessage} from 'element-plus';
import {ref,getCurrentInstance} from 'vue';
import {useStore} from 'vuex';

const {proxy} = getCurrentInstance()
const loading = ref(false)

const store = useStore()
const userId = store.getters.userId

/**
 * 获取列表
 * @param purpose
 */
const getSignDetailByUser = (purpose) =>{
  loading.value = true
  getSignDetailByUserApi(currentPage.value,pageSize.value,userId,purpose)
      .then(res=>{
        let data = res.data.result
        for(let i=0;i<data.length;i++){
          data[i].antiFakeTime = dateFormat("YYYY-mm-dd HH:MM:SS",new Date(data[i].antiFakeTime))
        }
        useSignTable.value = data
        loading.value = false
      }).catch(res=>{
    ElMessage.error(res)
  })
}
/**
 * 获取数量
 * @param purpose
 */
const getSignDetailNumByUser = (purpose) => {
  getSignDetailNumByUserApi(userId,purpose)
      .then(res=>{
        let data = res.data.result
        totalNum.value = data
      }).catch(res=>{
    ElMessage.error(res)
  })
}

// 签署文件--分页代码
const totalNum = ref(0)
const currentPage=ref(1)
const pageSize=ref(10)

const handleCurrentChange = (currPage) => {
  currentPage.value = currPage
  getSignDetailByUser(0)
  window.scrollTo(0, 175);
}

const handleSizeChange = (val) => {
  pageSize.value=val
  getSignDetailNumByUser(0)
}

/**
 * 获取 文件签署 列表
 */
getSignDetailByUser(0)
getSignDetailNumByUser(0)
const useSignTable = ref([])

/**
 * 跳转到签署文件的详情页
 * @param index
 * @param row
 */
const getDetail = (index,row) => {
  proxy.$router.push({
    path:'/detail/use-detail',
    query:{
      antiFakeSealId: row.antiFakeSealId
    }
  })
}
</script>

<style scoped>
.status_icon{
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: red;
  display: inline-block;
  position: relative;
  vertical-align: middle;
  margin-right: 6px;
}

/deep/ .el-button--text{
  color: #1063f1;
  font-weight: 500;
  font-size: 13.5px;
  font-family: 微雅软黑,Arial;
}

/deep/ .el-pagination{
  margin: 20px 0;
}
</style>
